Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Thieves

TIME LIMIT = 1 SEC.

  • Every evening, hundreds of students gather up at canteen and buy various snacks. Many of these students prefer to pay through E-Wallets and UPI methods such as PayTM, PhonePe and Google Pay etc.
    Due to the rush, the owner can't keep track of all payments and verify if a student has actually made the payment or not. But the canteen owner has visual memory i.e. he can remember a few digits of phone numbers after looking at it just once. The digits that he can't remember, he marks them with the symbol '%'.
    Ex. For a phone number 1234567890, he may remember it as 1234%67%9%.
    Now, it is your job to find out whether a given set of students have made the payment or not.
Input Output
First line will contain N, number of students. Then the N phone numbers will follow.
Each of the next N lines consists of two ten digit numbers: the number that the canteen owner remembers and the corresponding actual number.
Print two space-separated integers - the number of students who made the payment and the number of students who did not.
Constraints
  • 1 ≤ T ≤ 100
  • Maximum number of digits per phone number in each test case = 10
Example Test Case
Input             Output
3
1234%67%9% 1234567890
349%%%%810 3497831233
56%%172273 5612172273
2  1
Solution

#include <iostream> #include <string> using namespace std; int main() { int n, i, j, c = 0; //c denotes the number of mismatched pairs of phone numbers. cin >> n; //take in number of numbers. string ip[n][2];//there are n pairs of phone numbers. for (i = 0; i < n; i++) ///take in all the pairs of phone numbers cin >> ip[i][0] >> ip[i][1]; for (i = 0; i < n; i++) //checking each pair. { for (j = 0; j < 10; j++) //checking corresponding characters in the phone numbers. { if (ip[i][0][j] != ip[i][1][j] && ip[i][0][j] != '%') { //if the digit is known and it is not equal then the numbers do not match. c++; break; } } } cout << n - c << " " << c; // n-c gives the matching pairs of phone numbers return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();